package com.nai365.nart.member.controller;

import com.nai365.nart.common.core.util.R;
import com.nai365.nart.member.entity.UserBank;
import com.nai365.nart.member.service.UserBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/userBank" )
@Api(value = " UserBank", tags = "用户银行卡")
public class UserBankController {


	private final UserBankService userBankService;
	/**
	 * 新增用户银行卡表
	 * @param userBank 新增用户银行卡表
	 * @return R
	 */
	@ApiOperation(value = "新增用户银行卡表", notes = "新增用户银行卡表")
	@PostMapping("/saveUserBank")
	public R<Boolean> saveUserBank(@RequestBody UserBank userBank) {

		return R.ok(userBankService.saveUserBank(userBank),"保存成功!");
	}

	@ApiOperation(value = "通过userId查询用户银行卡信息", notes = "通过userId查询用户银行卡信息")
	@GetMapping("/{userId}" )
	public R<UserBank> findUserBankByUserId(@PathVariable("userId" ) Long userId) {

		return R.ok(userBankService.findUserBankByUserId(userId));
	}

	/**
	 * 修改银行卡信息
	 * @param userBank
	 * @param
	 */
	@ApiOperation(value = "修改用户银行卡信息", notes = "修改用户银行卡信息")
	@PostMapping("/updateUserBank")
	public R<Boolean> updateUserBank(@RequestBody UserBank userBank){
		Boolean isSuccess=userBankService.updateUserBank(userBank);
		return R.ok(isSuccess,"修改成功！");
	}

}
